package com.chenjun.core.service.oa.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chenjun.common.bean.Pagination;
import com.chenjun.common.model.DataGridModel;
import com.chenjun.core.dao.generator.entity.OaBillLeaveApplication;
import com.chenjun.core.dao.generator.mapper.OaBillLeaveApplicationMapper;
import com.chenjun.core.dao.module.OaBillLeaveApplicationRelationMapper;
import com.chenjun.core.service.oa.LeaveManagerService;

@Service
@Transactional
public class LeaveManagerServiceImpl implements LeaveManagerService {
	
	@Resource
	private OaBillLeaveApplicationMapper leaveMapper;
	
	@Resource
	private OaBillLeaveApplicationRelationMapper leaveRelationMapper;

	@Override
	public OaBillLeaveApplication get(Integer id) {
		return leaveMapper.selectByPrimaryKey(id);
	}

	@Override
	public int delete(Integer id) {
		return leaveMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int createOrUpdate(OaBillLeaveApplication record) {
		int rows = 0;
		if (record.getId() == null) {
			rows = leaveMapper.insert(record);
		} else {
			rows = leaveMapper.updateByPrimaryKeySelective(record);
		}
		return rows;
	}

	@Override
	public Pagination doPagination(DataGridModel param) {
		Pagination vo = new Pagination();
		List<OaBillLeaveApplication> list = leaveRelationMapper.selectByCondition(param);
		param.setStart(0);
		param.setRows(0);
		int size = leaveRelationMapper.countByCondition(param);
		vo.setAaData(list);
		vo.setiTotalRecords(size);
		vo.setsEcho(param.getPage());
		vo.setiTotalDisplayRecords(size);
		return vo;
	}

	@Override
	public List<OaBillLeaveApplication> doListByCondition(DataGridModel param) {
		return leaveRelationMapper.selectByCondition(param);
	}

}
